package com.smartlink.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.smartlink.pojo.CT;

public class CTDaoImpl implements Dao<Integer, CT> {

	private SessionFactory sessionFactory;
	private Session session;

	public Session getSession() {
		this.session=sessionFactory.getCurrentSession();
		return session;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public boolean insert(CT v) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean delete(CT v) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteById(Integer k) {
		String hql="DELETE FROM CT WHERE id=?";
		getSession().createQuery(hql).setInteger(0, k).executeUpdate();
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean update(CT v) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public CT findById(Integer k) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<CT> getAll() {
		// TODO Auto-generated method stub

		return null;
	}
	
	public List<CT> getAll(Integer clsroomId) {
		// TODO Auto-generated method stub
		String hql="FROM CT ct LEFT JOIN FETCH ct.teacher WHERE ct.classroom=?";
		Query query=getSession().createQuery(hql);
		query.setInteger(0, clsroomId);
		@SuppressWarnings("unchecked")
		List<CT> ctList=query.list();
		return ctList;
	}

	@Override
	public List<CT> getAll(Integer currentIndex, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

}
